home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 4.9 KB | 186 lines | [TEXT/KAHL] |
- /********************************************************* DEFINITION
- DATE: 9/24/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPStaticText
-
- SUPERCLASS: CPPVisualObject
-
- This C++ class manages a static string
-
- ********************************************************************/
-
- #include <CPPStaticText.h>
- #include <CPPWindow.h>
- #include <MemoryTools.h>
- #include <StringTools.h>
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- CPPStaticText::CPPStaticText (CPPWindow *itsWindow, Rect *itsBounds,
- int StrID, int Font, int FSize,
- int FJust, int FStyle,
- RGBColor *FColor, Boolean canBeTarget,
- Boolean active, Boolean visible) :
- CPPVisualObject (itsWindow, itsBounds, canBeTarget,
- active, visible)
- {
- StringHandle tempHandle = GetString(StrID);
-
- if (tempHandle)
- {
- this->itemText = (StringPtr)Hand2Ptr((Handle)tempHandle);
- ReleaseResource((Handle)tempHandle);
- }
- else
- this->itemText = NULL;
-
- MakeStatText (itsBounds, Font, FSize, FJust, FStyle, FColor);
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPStaticText::CPPStaticText (CPPWindow *itsWindow, Rect *itsBounds,
- StringPtr theString, int Font,
- int FSize, int FJust,
- int FStyle, RGBColor *FColor,
- Boolean canBeTarget, Boolean active,
- Boolean visible) :
- CPPVisualObject (itsWindow, itsBounds, canBeTarget,
- active, visible)
- {
- if (theString)
- this->itemText = String2String (theString);
- MakeStatText (itsBounds, Font, FSize, FJust, FStyle, FColor);
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPStaticText::~CPPStaticText (void)
- {
- if (this->itemText)
- DisposPtr((Ptr)this->itemText);
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPStaticText::ClassName (void)
- {
- return "CPPStaticText";
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPStaticText::Draw (void)
- {
- RGBColor OldColor;
-
- if (this->owningWindow && this->itemText && this->IsVisible())
- {
- // save the old values for the font, face, style & color
- short OldFont = this->owningWindow->txFont;
- short OldSize = this->owningWindow->txSize;
- short OldFace = this->owningWindow->txFace;
-
- if (this->InColorWindow())
- {
- GetForeColor(&OldColor);
- RGBForeColor(&this->fontColor);
- }
- TextSize (this->fontSize);
- TextFont (this->fontID);
- TextFace (this->fontStyle);
- TextBox (this->itemText+1, *this->itemText,
- &this->bounds, this->fontJust);
-
- // restore the old font attributes
- this->owningWindow->txFont = OldFont;
- this->owningWindow->txSize = OldSize;
- this->owningWindow->txFace = OldFace;
- if (this->InColorWindow())
- RGBForeColor(&OldColor);
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPStaticText::MakeVisible (Boolean nowVisible)
- /* hide or show the text item */
- {
- if (!nowVisible)
- EraseRect (GetBounds());
- InvalRect (GetBounds());
-
- CPPVisualObject::MakeVisible(nowVisible);
- }
-
- /*-----------------------------------------------------------------*/
-
- Rect *CPPStaticText::GetBounds (void)
- {
- return &this->bounds;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPStaticText::MoveContent (short newH, short newV)
- {
- OffsetRect (&this->bounds, newH - this->bounds.left,
- newV - this->bounds.top);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPStaticText::ResizeContent (short newWidth, short newHeight)
- {
- this->bounds.right = this->bounds.left+newWidth;
- this->bounds.bottom = this->bounds.top+newHeight;
- }
-
-
- /*-----------------------------------------------------------------*/
-
- void CPPStaticText::SetitsString (StringPtr newString, Boolean keepCopy)
- {
- GrafPtr SavePort;
-
- GetPort(&SavePort);
- SetPort(this->owningWindow);
-
- if (this->itemText)
- DisposPtr((Ptr)this->itemText);
- if (keepCopy)
- this->itemText = String2String(newString);
- else
- this->itemText = newString;
-
- // force the string to redraw
- EraseRect(GetBounds());
- InvalRect(GetBounds());
-
- SetPort(SavePort);
- }
-
- /*-----------------------------------------------------------------*/
-
- StringPtr CPPStaticText::GetitsString (void)
- {
- return this->itemText;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPStaticText::MakeStatText (Rect *itsBounds, short Font,
- short FSize, short FJust,
- short FStyle,
- RGBColor *FColor)
- {
- this->bounds = *itsBounds;
- this->fontID = Font;
- this->fontSize = FSize;
- this->fontJust = FJust;
- this->fontStyle = FStyle;
- this->fontColor = *FColor;
- }